from time import sleep
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from webdriver_manager.chrome import ChromeDriverManager

# 编写自动化脚本的具体步骤
# 1. 打开浏览器 -- 驱动管理器
# ChromeIns=ChromeDriverManager().install()
# ## 创建谷歌浏览器驱动对象
# driver=webdriver.Chrome(service=Service(ChromeIns))
# 用本地webdriver代替install，install太慢了
driver=webdriver.Chrome()
sleep(2)
# 2. 输入百度网址: https://www.baidu.com/ (网址一定要完整，不要写成 www.baidu.com)
driver.get("https://www.baidu.com/")
sleep(2)
# 3. 找到百度输入框，输入关键词"你好"
driver.find_element(By.CSS_SELECTOR,"#chat-textarea").send_keys("你好")
sleep(2)
# 4. 点击"百度一下"按钮
driver.find_element(By.CSS_SELECTOR,"#chat-submit-button").click()
sleep(2)
# 5. 关闭浏览器
driver.quit()